package cn.tedu.ivos.dict.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.AddDictParam;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "字典管理")
@Slf4j
@RequestMapping("/v1/dict/")
public class DictController {
    @Autowired
    DictService service;
    @Operation(summary = "字典列表")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult dictSelect(@Validated DictQuery query){
        log.debug("query:{}",query);
        List<DictVO> list = service.dictSelect(query);
        return JsonResult.ok(list);
    }

    @Operation(summary = "保存字典")
    @ApiOperationSupport(order = 20)
    @PostMapping("save")
    public JsonResult addDict(@Validated AddDictParam param){
        service.addDict(param);
        return JsonResult.ok();
    }
    @Operation(summary = "删除字典")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete/{id}")
    public JsonResult deleteDict(@PathVariable Long id){
        log.debug("删除字典,参数={}",id);
        service.deleteDict(id);
        return JsonResult.ok();
    }
}
